package com.ruoyi.analysiswarning.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.analysiswarning.domain.ScriptApp;
import com.ruoyi.analysiswarning.mapper.ScriptAppMapper;
import com.ruoyi.analysiswarning.service.IScriptAppService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ScriptAppService implements IScriptAppService {

    @Resource
    ScriptAppMapper scriptAppMapper;

    @Log(title = "脚本查询", businessType = BusinessType.QUERY)
    @Override
    public List<ScriptApp> queryScriptAppByType(String type,String status) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("type",type);
        if(!"".equals(status) && !"undefined".equals(status)){
            wrapper.eq("state",status);

        }

        // 三种不同数据循环展示
        wrapper.eq("daily_display",DateUtil.dayOfMonth(new Date())%3);

        List<ScriptApp> list = scriptAppMapper.selectList(wrapper);

        return list;
    }

    @Override
    public List<ScriptApp> queryScriptAppByTypeNew(String type) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("type",type);
//        wrapper.or();
//        wrapper.eq("type",7);
//        wrapper.or();
//        wrapper.eq("type",8);

        List<ScriptApp> list = scriptAppMapper.selectList(wrapper);
        return list;
    }


    @Override
    public int updateScriptAppById(Integer id,Integer state) {
        if(state == 0){
            return scriptAppMapper.updateScriptAppByIdz(id);
        }
        return scriptAppMapper.updateScriptAppById(id);
    }

    @Override
    public List<ScriptApp> queryScriptAppIng(Integer t) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("state",1);
        wrapper.eq("time",t);
        List<ScriptApp> list = scriptAppMapper.selectList(wrapper);
        return list;
    }
}
